package org.mashibing.dto;

import lombok.Data;
import lombok.experimental.Accessors;
import org.mashibing.constant.CommonStatusEnum;

/**
 * @author:
 * @create: 2024/3/19 17:33
 * @description: 统一返回格式
 */
@Data
@Accessors(chain = true)
public class ResponseResult<T> {

    private int code;

    private String message;

    private T data;

    /**
     * 无参数成功
     */
    public static <T> ResponseResult success(){
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getValue());
    }

    /**
     * 成功
     */
    public static <T> ResponseResult success(T data){
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getValue())
                .setData(data);
    }

    /**
     * 失败：统一失败
     */
    public static <T> ResponseResult fail(String data){
        return new ResponseResult().setData(data);
    }

    /**
     * 失败：自定义错误码、错误信息
     */
    public static <T> ResponseResult fail(int code,String message){
        return new ResponseResult().setCode(code)
                .setMessage(message);
    }

    /**
     * 失败：自定义错误码、错误信息、具体错误
     */
    public static <T> ResponseResult fail(int code,String message,String data){
        return new ResponseResult().setCode(code)
                .setMessage(message)
                .setData(data);
    }
}
